The Ne comes from NeDB, and ko refers to the Japanese diminuitive “ko” (小) or little.

What is Nedb?

NeDB is a lightweight database written entirely in Javascript, and that implements the well-known and loved MongoDB API. It is packaged as a Node module that be used with a simple require and can be used as an in-memory only or persistent datastore. You can think of it as SQLite for MongoDB projects.

NekoDB comes with NeDB built in, so you can access a Mongo-like database, without actually installing or running a database at all. NeDB is suitable for datasets in the range of tens of thousands of documents. It is perfect for develop or small & medium websites. For larger datasets, it is recommended you upgrade to MongoDB.

  • To build the simplest, easiest to use ODM
  • Stay as close to MongoDB syntax as possible
    • Provide model validation and model referencing
    • Beyond that, just provide a thin wrapper over the native functionality
  • Support NeDB and MongoDB with an identical interface
  • Promisify NeDB: no callback hell, only lovely Promises
  • You can use it as async await in nodejs 7.6 & more

Connecting and creating schemas

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const ko = require('nekodb')

ko.connect({
client: 'nedb',
filepath: __dirname + '/db'

})

Or

ko.connect({
client: 'nedb',
inMemory: true

})

ko.models({
Celebrity: {
name: ko.String[50],
age: ko.Number.integer(),
birthday: ko.Date,
instagram: ko.String[30],
followers: ko.Number
},
Family: {
name: ko.String,
members: [ko.models.Celebrity],
city: ko.String
}
})

if you want to connect mongodb rather than nedb

1
2
3
4
5
6
7
ko.connect({
client: 'mongodb',
username: 'root',
password: 'mongopassword',
address: 'localhost:27017',
database: 'nekodb'
})

or

1
2
3
4
ko.connect({
client: 'mongodb',
url: 'mongodb://username:password@localhost:27017/nekodb'
})

Creating a model

1
2
3
4
5
6
7
8
9
10
11
12
const celebrity = ko.models.Celebrity.create({
name: 'Kim Kardashian West',
age: 37,
birthday: new Date('1980-10-21'),
instagram: '@kimkardashian',
followers: 1080000
})

celebrity.save().then(instance => {
console.log(instance)
// instance will have been assigned an _id
})

if you want to use async await instead of promise call:

1
2
instance = await celebrity.save()
console.log(instance)

Finding models

1
2
3
4
5
6
7
ko.models.Celebrity.find({}).then(instances => {
console.log(instances)
})

ko.models.Celebrity.findOne({name: 'Kanye West'}).then(instance => {
console.log(instance)
})

Updating a model

1
2
3
4
ko.models.Celebrity.findOne({name: 'Kim Kardashian'}).then(instance => {
instance.name = 'Kim Kardashian West'
return instance.save()
})

Deleting models

1
2
3
ko.models.Celebrity.deleteOne({name: 'Johnny Depp'}).then(deletedCount => {
console.log(deletedCount)
})

that’s it.
It has more features that you can see them on NEKDODB